<#include "/common/layout.html">
<@body>
<body class="gray-bg">
	<div class="wrapper">
		<section class="content">
			<div class="row">
			<div class="col-xs-12">
				<div class="box">
				<div class="form-inline">
				<div class="box-header">
					<div class="input-group input-group-sm">
					<input type="text" name="search_value" id="search_value" class="form-control" placeholder="名称查询">
					<div class="input-group-btn">
						<a href="javascript:;" id="search_data" class="btn btn-default" ><i class="fa fa-search"></i> 搜索</a>
						<a href="javascript:;" id="search_refresh" class="btn btn-default"><i class="fa fa-refresh"></i> 重置</a>
					</div>
					</div>
				</div>
				</div>
				<div class="box-body">
					<table id="stock_initTable" class="table table-bordered table-hover">
					</table>
				</div>
				</div>
			</div>
			</div>
		</section>
	</div>
</body>
</@body>
<script>
	var editFlag = '${shiro.hasPermission("editStock")}';
	var query_data = {
		search: ''
	}
	var options = {
		id: "stock_initTable",
		lengthMenu: [5, 10, 20, 50],
		pageLength: 5,
		ajax: {
			url: "${request.contextPath}/mall/stock/listPage",
			type: "POST",
			data: query_data,
		},
		headerCallback: function(e, a, t, n, s) {
			e.getElementsByTagName("th")[0].innerHTML = '<label class="m-checkbox"><input type="checkbox" class="minimal m-group-checkable" value="root"></label>';
			$(e.getElementsByTagName("th")).parent().css("background-color", "#f7f7fa");
		},
		columnDefs: [{
			targets: 0,
			width: "30px",
			orderable: !1,
			render: function(e, a, t, n) {
				return '<label class="m-checkbox"><input type ="checkbox" class="minimal m-checkable" value="' + t.id + '"></label>';
			}
		},{
			targets: 1,
			title: "商品编码",
			orderable: !1,
			render: function(e, a, t, n) {
				if (t.goodSn != null) {
					return t.goodSn;
				} else {
					return "";
				}
			}
		},{
			targets: 2,
			title: "商品图片",
			orderable: !1,
			render: function(e, a, t, n) {
				return $.table.imageSquareView(t.picUrl);
			}
		},{
			targets: 3,
			title: "商品名称",
			orderable: !1,
			render: function(e, a, t, n) {
				if (t.goodName != null) {
					return t.goodName;
				} else {
					return "";
				}
			}
		},{
			targets: 4,
			title: "商品库存",
			orderable: !1,
			render: function(e, a, t, n) {
				var html='';
				if (t.stockNum != null) {
					if(t.specType){
						html += t.stockNum + '<font style="color:#ff851b;">（单一规格数量）</font>';
					}else{
						html += t.stockNum + '<font style="color:#ff851b;">（多种规格总量）</font>';
					}
					return html;
				} else {
					return html;
				}
			}
		},{
			targets: 5,
			title: "操作",
			orderable: !1,
			render: function(e, a, t, n) {
				var actions = [];
				if(editFlag == 'true') {
					actions.push('<a class="btn btn-primary btn-xs dialog_detail" data-title="库存详情" data-url="${request.contextPath}/mall/stock/detail/'+ t.goodsId +'" title="详情"><i class="fa fa-search-plus"></i>详情</a>')
				}
				return actions.join('');
			}
		}]
	};
	//渲染表格
	data_oTable = $.table.init(options);
	//搜索
	$("#search_data").off().on("click", function() {
		query_data.search = $("#search_value").val();
		reloadTable();
	});
	//重置
	$("#search_refresh").off().on("click", function() {
		query_data.search = "";
		$("#search_value").val("");
		reloadTable();
	});
	//重新加载表格
	function reloadTable() {
		var oSetting = data_oTable.settings()[0];
		oSetting.ajax.data = query_data;
		data_oTable.draw();
	}
</script>
